      SUBROUTINE INADCK (*)
      COMMON /LONG/ ELONG(1)
      COMMON /LAT/ ELAT(1)
      COMMON /RESX/ N, TCOMP(1)
      COMMON /RESA/ ACOMP(1)
      COMMON /TEST/ ATABLE, LASTIT, RESSQ, DEBUG, SCPLOT, LASTPR, NCYCLE
      COMMON/PIG/ NA
      DOUBLE PRECISION RESID,AA,AC,AB,AD,ACAL,ACOMP,RES,ACC,YMAXD
      LOGICAL LOGPRT
      LOGICAL ATABLE, LASTIT, DEBUG, SCPLOT, LASTPR
      PARAMETER NACC = 550
      CHARACTER*4 IMAGE
      DIMENSION TIME (NACC), ACC (NACC), RES(NACC), IMAGE(25),
     1 FLONG(NACC)
      LOGICAL RESET
      DATA TOL /0.01/
      SAVE TIME,ACC,NAM,NACC,LONG,LAT,RESX,RESA,TEST,PIG
      NACA = NACC
      NA = 0
   10 READ (5, 20) NTYPE, T, A
   20 FORMAT(I5,2E15.7)
      IF (NTYPE .NE. 0) GO TO 70
      IF (NA .LT. NACC) GO TO 50
      WRITE (6, 30)
   30 FORMAT (35H1ERROR IN ORBSIM ACCELERATION TABLE)
      WRITE (6, 40) NACA
   40 FORMAT (11H0MORE THAN , I4, 18H ENTRIES IN TABLE.)
      RETURN 1
   50 NAM = NA
      NA = NA + 1
      TIME (NA) = T
      ACC (NA) = -A
      IF (NAM .EQ. 0) GO TO 10
      IF (TIME (NA) .GT. TIME (NAM)) GO TO 10
      WRITE (6, 30)
      WRITE (6, 60) TIME (NAM), TIME (NA)
   60 FORMAT (47H0TIMES NOT IN ASCENDING ORDER.  FOLLOWING TIME , E15.7,
     1 11H CAME TIME , E15.7)
      RETURN 1
   70 IF (NA .GT. 0) GO TO 90
      WRITE (6, 30)
      WRITE (6, 80)
   80 FORMAT (25H0NO ENTRIES IN THE TABLE.)
      RETURN 1
   90 RETURN
      ENTRY ACALC(RES,LOGPRT)
      IPAGE = 0
      LINES = 56
      RESSQ = 0.0
      TDEN = TCOMP(2) - TCOMP(1)
      TIMIN = TCOMP(1)
      TIMAX = TCOMP(N)
      I = 1
      IF(.NOT. LOGPRT) WRITE(6,*) 'INSIDE INADCK *NA=',NA,'*',
     *               'NCYCLE=',NCYCLE,'*RESSQ=',RESSQ,'*'
      DO 200 IA = 1, NA
      T = TIME(IA)
      TDELA = 0.0
      TDELB = 0.0
      IF (T .LT. TIMIN) GO TO 200
      IF (T .GT. TIMAX) GO TO 200
  110 TDEL = T - TCOMP(I)
      IF (ABS(TDEL) .LT. TOL) GO TO 120
      IF (TDEL) 140, 120, 130
  120 ACAL  = ACOMP(I)
      FLONG(IA) = ELONG(I)
      GO TO 180
  130 I = I + 1
      TDELA = TDEL
      IF (TDELB .LT. 0.0) GO TO 150
      GO TO 110
  140 TDELB = TDEL
      IF (TDELA .GT. 0.0) GO TO 150
      I = I - 1
      GO TO 110
  150 IF (I .GT. 2) GO TO 160
      I = 3
      TDELA = TDELA - TDEN
      TDELB = TDELB - TDEN
      GO TO 170
  160 IF (I .LT. N) GO TO 170
      I = N - 1
      TDELA = TDELA + TDEN
      TDELB = TDELB + TDEN
  170 H = (TDELA + TDELB)/TDEN
      AA = ACOMP(I-1) + ACOMP(I)
      AC = (ACOMP(I-2) + ACOMP(I+1) - AA)/16.0
      AA = 0.5*AA - AC
      AB = ACOMP(I) - ACOMP(I-1)
      AD = (ACOMP(I+1) - ACOMP(I-2) - 3.0*AB)/48.0
      AB = 0.5*AB - AD
      ACAL  = ((AD*H + AC)*H + AB)*H + AA
      AA = ELONG(I-1) + ELONG(I)
      AC = (ELONG(I-2) + ELONG(I+1) - AA)/16.0
      AA = 0.5*AA - AC
      AB = ELONG(I) - ELONG(I-1)
      AD = (ELONG(I+1) - ELONG(I-2) - 3.0*AB)/48.0
      AB = 0.5*AB - AD
      FLONG(IA) = ((AD*H + AC)*H + AB)*H + AA
  180 RESID = ACAL  - ACC(IA)
      RES(IA) = RESID
      RESSQ = RESSQ + RESID**2
      RELRES = RESID/ACC(IA)
      IF(.NOT. LASTPR) GO TO 200
      IF (LINES .LT. 56) GO TO 190
      IPAGE = IPAGE + 1
      LINES = 5
      WRITE (6, 185) IPAGE
  185 FORMAT (53H1COMPARISON OF CALCULATED AND TABULATED ACCELERATIONS,
     1 7H - PAGE, I3/ 10H0LONGITUDE, 12X, 4HTIME, 6X, 10HCALCULATED, 7X,
     2 9HTABULATED, 8X, 8HABSOLUTE, 8X, 8HRELATIVE/ 10H (DEGREES), 7X,
     3 9H(MINUTES), 4X, 12HACCELERATION, 4X, 12HACCELERATION, 7X,
     4 9HRESIDUALS, 7X, 9HRESIDUALS/)
  190 WRITE (6, 195) FLONG(IA), T, ACAL, ACC(IA), RESID, RELRES
  195 FORMAT (F10.2, F16.2, 4F16.8)
      LINES = LINES + 1
  200 CONTINUE
      IF(LOGPRT)RETURN
      IF (.NOT. LASTPR) GO TO 290
C
C     PRINTER PLOT OF RESIDUAL DIFFERENCES BETWEEN TABULATED AND
C     CALCULATED ACCELERATIONS
C
      RESET = .TRUE.
      NCHAR = 100
      IPAGE = 0
      LINES = 56
      YLO = YMAXD (RES, NA)
      CALL SCALES (YLO, YHI)
      YLO = -YHI
      DO 270 IA = 1, NA
      XNUBLE=REAL(RES(IA))
      CALL PRPL (XNUBLE, 'R', IMAGE, NCHAR, YLO, YHI, RESET)
      IF (LINES - 54) 250, 210, 220
  210 CALL ENDSC
  220 IPAGE = IPAGE + 1
      LINES = 5
      WRITE (6, 230) IPAGE
  230 FORMAT (52H1PLOT OF RESIDUAL DIFFERENCES BETWEEN TABULATED AND ,
     1 31HCALCULATED ACCELERATIONS - PAGE, I3)
      CALL ENDSC
      WRITE (6, 240)
  240 FORMAT ( 8X, 16HLONGITUDE   TIME/  8X, 16H(DEGREES)  (MIN))
  250 WRITE (6, 260) FLONG(IA), TIME(IA), IMAGE
  260 FORMAT (10X, 2F7.2,  8X, 25A4)
      LINES = LINES + 1
  270 CONTINUE
      CALL ENDSC
      WRITE (6, 280)
  280 FORMAT (1H1)
  290 WRITE (6, 300) NCYCLE, RESSQ
  300 FORMAT (/19H0ORBSIM EVALUATION , I3,
     1 28H.  RESIDUAL SUM OF SQUARES =, E13.8)
      RETURN
      END
